//
//  OrderDetailViewController.m
//  SalonManage
//
//  Created by tim on 2017/7/30.
//  Copyright © 2017年 lmtt. All rights reserved.
//

#import "OrderDetailViewController.h"
#import "ImgBrowseController.h"
#import "CustomerListController.h"
#import "FeedbackViewController.h"
#import "ProjectListViewController.h"

#import "ServerItemCell.h"
#import "LMSectionView.h"

@interface OrderDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UIView *contentView;

@property (nonatomic,strong) UIView * searchView;
@property (nonatomic,strong) LMCellView * customView;
@property (nonatomic,strong) LMCellView * phoneView;
@property (nonatomic,strong) LMCellView * serviceView;
@property (nonatomic,strong) LMButton * addBtn;

@property (nonatomic,strong) UITableView * mainTableView;


@end

@implementation OrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitle:@"项目选择"];
    [self initWithSubViews];
}

-(void)initWithSubViews{
    self. contentView.frame = CGRectMake(0, 64, __kScreenWidth, __kScreenHeight - 64);
    self.contentView.backgroundColor = HGCOLOR(@"ffffff");
    [self.view addSubview:self.contentView];
    
    //搜索视图
    [self.contentView addSubview:self.searchView];
    [self.searchView addSubview:self.customView];
    [self.searchView addSubview:self.phoneView];
    [self.searchView addSubview:self.serviceView];
    [self.searchView addSubview:self.addBtn];
    
    
    self.searchView.frame = CGRectMake(0, 0, __kScreenWidth, HGADPT(220));
    
    self.customView.frame = CGRectMake(0, HGADPT(10), __kScreenWidth-60, HGADPT(60));
    self.phoneView.frame =  CGRectMake(0, self.customView.bottom+HGADPT(10), self.customView.width, self.customView.height);
    self.serviceView.frame =  CGRectMake(0, self.phoneView.bottom+HGADPT(10), self.phoneView.width, self.phoneView.height);
    self.addBtn.frame = CGRectMake(0, 0, 90, 30);
    self.addBtn.centerY = self.searchView.centerY;
    self.addBtn.right = __kScreenWidth-HGADPT(30);
    
    
    self.navigationController.navigationBar.translucent = NO;
    self.automaticallyAdjustsScrollViewInsets = NO;
    self. mainTableView= [[UITableView alloc] initWithFrame:CGRectMake(0, self.searchView.bottom, __kScreenWidth, __kScreenHeight-64-HGADPT(220)) style:UITableViewStyleGrouped];
    
    self. mainTableView.delegate = self;
    self. mainTableView.dataSource = self;
    self. mainTableView.separatorColor = [UIColor clearColor];
    self. mainTableView.showsVerticalScrollIndicator=NO;
    self. mainTableView.showsHorizontalScrollIndicator=NO;
    [self.contentView addSubview:self. mainTableView];
}

#pragma mark - UITableViewDataSource
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return HGADPT(108);
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return HGADPT(244)+HGADPT(240);
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return HGADPT(160);
}

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{
    
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 3;
 
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ServerItemCell *cell = [ServerItemCell serverItemCellWithTableView:tableView ];
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * headView = [[UIView alloc]init];
    headView.backgroundColor = kBGColor;
    LMSectionView * labelView = [LMSectionView sectionViewWithHeight:HGADPT(88) font:_kFont30 color:kColor3C3C3C title:@"美发项目"];
    labelView.top = HGADPT(20);
    labelView.backgroundColor = [UIColor whiteColor];
    [headView addSubview:labelView];
    return headView;
}


-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView * footView = [[UIView alloc]init];
    footView.backgroundColor = [UIColor whiteColor];
    LMCellView * totalPrice = [LMCellView cellViewWithNoActionHeight:HGADPT(30)];
    totalPrice.top = HGADPT(20);
    totalPrice.textLabel.text = @"合计金额：";
    totalPrice.detailFied.text = @"100元";
    totalPrice.textLabel.font =totalPrice.detailFied.font= _kFontSub;
    totalPrice.detailLeft = HGADPT(190);
    [totalPrice removeLine];
    [footView addSubview:totalPrice];
    
    LMCellView * hairLabel = [LMCellView cellViewWithNoActionHeight:HGADPT(30)];
    hairLabel.top = totalPrice.bottom+HGADPT(4);
    hairLabel.textLabel.text = @"发型师：";
    hairLabel.detailFied.text = @"赵四";
    hairLabel.textLabel.font =hairLabel.detailFied.font= _kFontSub;
    hairLabel.detailLeft = HGADPT(190);
    [hairLabel removeLine];
    [footView addSubview:hairLabel];
    
    LMCellView * tecLabel = [LMCellView cellViewWithNoActionHeight:HGADPT(30)];
    tecLabel.top = hairLabel.bottom+HGADPT(4);
    tecLabel.textLabel.text = @"技师：";
    tecLabel.detailFied.text = @"小沈阳";
    tecLabel.textLabel.font =tecLabel.detailFied.font= _kFontSub;
    tecLabel.detailLeft = HGADPT(190);
    [tecLabel removeLine];
    [footView addSubview:tecLabel];
    
    LMCellView * assiLabel = [LMCellView cellViewWithNoActionHeight:HGADPT(30)];
    assiLabel.top = tecLabel.bottom+HGADPT(4);
    assiLabel.textLabel.text = @"助理：";
    assiLabel.detailFied.text = @"小王";
    assiLabel.textLabel.font =assiLabel.detailFied.font= _kFontSub;
    assiLabel.detailLeft = HGADPT(190);
    [assiLabel removeLine];
    [footView addSubview:assiLabel];
    
    LMCellView * beginLabel = [LMCellView cellViewWithNoActionHeight:HGADPT(30)];
    beginLabel.top = assiLabel.bottom+HGADPT(4);
    beginLabel.textLabel.text = @"开始时间：";
    beginLabel.detailFied.text = @"2017.4.8 12:00";
    beginLabel.textLabel.font =beginLabel.detailFied.font= _kFontSub;
    beginLabel.detailLeft = HGADPT(190);
    [beginLabel removeLine];
    [footView addSubview:beginLabel];
    
    LMCellView * finshLabel = [LMCellView cellViewWithNoActionHeight:HGADPT(30)];
    finshLabel.top = beginLabel.bottom +HGADPT(4);
    finshLabel.textLabel.text = @"结束时间：";
    finshLabel.detailFied.text = @"2017.5.18 13:00";
    finshLabel.textLabel.font =finshLabel.detailFied.font= _kFontSub;
    finshLabel.detailLeft = HGADPT(190);
    [finshLabel removeLine];
    [footView addSubview:finshLabel];
    
    UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, finshLabel.bottom+HGADPT(20), __kScreenWidth, HGADPT(20))];
    lineView.backgroundColor = kBGColor;
    [footView addSubview:lineView];
    
    UIView * bottomView = [[UIView alloc]initWithFrame:CGRectMake(0,lineView.bottom+HGADPT(20) , __kScreenWidth, HGADPT(220))];
    [footView addSubview:bottomView];
    
    NSArray * topArr = @[@"结束服务",@"价格表"];
    CGFloat topWidth = __kScreenWidth/2-HGADPT(43);
    CGFloat topHeight = HGADPT(60);
    for (int i = 0; i< 2; i++) {
        LMButton * actionBtn = [LMButton lm_buttonWithType:LMButtonTypeMove title:topArr[i]];
        actionBtn.frame = CGRectMake(HGADPT(30)*(i+1)+i*topWidth, HGADPT(40), topWidth, topHeight);
        actionBtn.tag = 100+i;
        [actionBtn addTarget:self action:@selector(actionBtn:) forControlEvents:UIControlEventTouchUpInside];
        [bottomView addSubview:actionBtn];
    }
    
    NSArray * bottomArr = @[@"客人信息",@"更改信息",@"撤销订单"];
    CGFloat bottomWidth = __kScreenWidth/3-HGADPT(40);

    for (int i = 0; i< 3; i++) {
        LMButton * actionBtn = [LMButton lm_buttonWithType:LMButtonTypeMove title:bottomArr[i]];
        actionBtn.frame = CGRectMake(HGADPT(30)*(i+1)+i*bottomWidth, HGADPT(120), bottomWidth, topHeight);
        actionBtn.tag = 200+i;
        [actionBtn addTarget:self action:@selector(bottonBtn:) forControlEvents:UIControlEventTouchUpInside];
        [bottomView addSubview:actionBtn];
    }
    return footView;
}
#pragma mark - action

-(void)actionBtn:(UIButton *)btn{
    NSInteger index = btn.tag- 100;
    if (index == 0) {//结束服务
        FeedbackViewController * next = [[FeedbackViewController alloc]init];
        [self.navigationController pushViewController:next animated:YES];
    }else{//显示价格单
        ImgBrowseController * imgVC =[[ImgBrowseController alloc]init];
        [self.navigationController pushViewController:imgVC animated:YES];
    }
}


-(void)bottonBtn:(UIButton *)btn{
    
    NSInteger index = btn.tag- 200;
    if (index == 0) {//客户信息
//        CustomerListController * customVC = [[CustomerListController alloc]init];
//        [self.navigationController pushViewController:customVC animated:YES];
    }else if (index== 1){//更改工号
        [self.navigationController popViewControllerAnimated:YES];
    }else{//撤销助理单
        
    }
}

#pragma mark -懒加载

-(UIView *)contentView{
    if (_contentView == nil) {
        _contentView = [[UIView alloc]init];
    }
    return _contentView;
}

-(UIView *)searchView{
    if (_searchView == nil) {
        _searchView = [[UIView alloc]init];
        
    }
    return _searchView;
}
-(LMCellView *)customView{
    if (_customView == nil) {
        _customView = [LMCellView cellViewWithHeight:HGADPT(60) clickHandler:^{
            
        }];
        _customView.textLabel.text = @"姓名：";
        _customView.detailFied.placeholder = @"请输入客户名";
        _customView.detailLeft = HGADPT(120);
        [_customView removeLine];
    }
    return _customView;
}

-(LMCellView *)phoneView{
    if (_phoneView == nil) {
        _phoneView = [LMCellView cellViewWithHeight:HGADPT(60) clickHandler:^{
            
            
        }];
        _phoneView.textLabel.text = @"号码：";
        _phoneView.detailFied.placeholder = @"请输入客户手机号";
        _phoneView.detailLeft = HGADPT(120);
        [_phoneView removeLine];
    }
    return _phoneView;
}

-(LMCellView *)serviceView{
    if (_serviceView == nil) {
        _serviceView = [LMCellView cellViewWithHeight:HGADPT(60) clickHandler:^{
            
            
        }];
        _serviceView.textLabel.text = @"类型：";
        _serviceView.detailFied.placeholder = @"请输入服务类型";
        _serviceView.detailLeft = HGADPT(120);
        [_serviceView removeLine];
    }
    return _serviceView;
}

-(LMButton *)addBtn{
    if (_addBtn == nil) {
        _addBtn = [LMButton lm_buttonWithType:LMButtonTypeBorderLine title:@"添加"];
        kWeakSelf(self)
        _addBtn.onClick = ^(LMButton *btn) {
            ProjectListViewController * next = [[ProjectListViewController alloc]init];
            [weakself.navigationController pushViewController:next animated:YES];
            
        };
    }
    return _addBtn;
}


@end
